# $Id: PKGBUILD 177953 2013-02-12 12:13:50Z thomas $
# Maintainer: Eric Bélanger <eric@archlinux.org>
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgbase=lvm2
pkgname=('lvm2' 'device-mapper')
pkgver=2.02.98
pkgrel=3
arch=('i686' 'x86_64')
url="http://sourceware.org/lvm2/"
license=('GPL2' 'LGPL2.1')
groups=('base')
source=(ftp://sources.redhat.com/pub/lvm2/LVM2.${pkgver}.tgz{,.asc}
        lvm2_install
        lvm2_hook
        11-dm-initramfs.rules
        lvm2.conf
        dmeventd.service
        dmeventd.socket
        lvm-monitoring.service
        lvmetad.service
        lvmetad.socket)
sha1sums=('077425115b164c335a9930df745943e9ea666a8a'
          '4713c852fc668e6fbd36ff7c6b5675b10a95a0f8'
          '8008547b133af89f79461a6df5412539ed3f26b7'
          'ff0fdf0a3005a41acd4b36865056109effc3474b'
          'f6a554eea9557c3c236df2943bb6e7e723945c41'
          'ccefad65fde3d50331a42b0e90a1539dc7c8b9e4'
          'cbc64f377fbb1c1a9ff53bc6ca85c324075499b7'
          '1d56f47a81350ae37ffbf61ee036fe31f4c5d504'
          'ae945cae2d71b286439a9945876acb78dc9eeaf7'
          '460b094e8689298ed59842d1abcee5d4e706e1d7'
          'fcfc265e3b10294cc4b10949a342e9db4310b186')

build() {
  cd "${srcdir}/LVM2.${pkgver}"
  unset LDFLAGS

  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-udev-prefix=/usr \
    --with-systemdsystemunitdir=/usr/lib/systemd/system --with-default-pid-dir=/run \
    --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm \
    --enable-pkgconfig --enable-readline --enable-dmeventd --enable-cmdlib --enable-applib \
    --enable-udev_sync --enable-udev_rules --with-default-locking-dir=/run/lock/lvm \
    --enable-lvmetad
  make
}

package_device-mapper() {
  pkgdesc="Device mapper userspace library and tools"
  url="http://sourceware.org/dm/"
  depends=('glibc' 'udev')

  cd "${srcdir}/LVM2.${pkgver}"
  make DESTDIR="${pkgdir}" install_device-mapper
  # extra udev rule for device-mapper in initramfs
  install -D -m644 "${srcdir}/11-dm-initramfs.rules" "${pkgdir}/usr/lib/initcpio/udev/11-dm-initramfs.rules"
  # Install dmeventd socket and service
  install -D -m644 "${srcdir}/dmeventd.service" "${pkgdir}/usr/lib/systemd/system/dmeventd.service"
  install -D -m644 "${srcdir}/dmeventd.socket" "${pkgdir}/usr/lib/systemd/system/dmeventd.socket"
  install -d -m755 "${pkgdir}/usr/lib/systemd/system/sockets.target.wants"
  ln -sf /usr/lib/systemd/system/dmeventd.socket "${pkgdir}/usr/lib/systemd/system/sockets.target.wants/dmeventd.socket"
}

package_lvm2() {
  pkgdesc="Logical Volume Manager 2 utilities"
  depends=('bash' "device-mapper>=${pkgver}" 'udev' 'readline')
  conflicts=('lvm' 'mkinitcpio<0.7')
  backup=('etc/lvm/lvm.conf')
  options=('!makeflags')
  install=lvm2.install

  cd "${srcdir}/LVM2.${pkgver}"
  make DESTDIR="${pkgdir}" install_lvm2
  # install applib
  make -C liblvm DESTDIR="${pkgdir}" install
  # /etc directories
  install -d "${pkgdir}"/etc/lvm/{archive,backup}
  # mkinitcpio hook
  install -D -m644 "${srcdir}/lvm2_hook" "${pkgdir}/usr/lib/initcpio/hooks/lvm2"
  install -D -m644 "${srcdir}/lvm2_install" "${pkgdir}/usr/lib/initcpio/install/lvm2"
  # systemd support
  install -D -m644 "${srcdir}/lvm2.conf" "${pkgdir}/usr/lib/tmpfiles.d/lvm2.conf"
  install -D -m644 "${srcdir}/lvm-monitoring.service" "${pkgdir}/usr/lib/systemd/system/lvm-monitoring.service"
  install -D -m644 "${srcdir}/lvmetad.service" "${pkgdir}/usr/lib/systemd/system/lvmetad.service"
  install -D -m644 "${srcdir}/lvmetad.socket" "${pkgdir}/usr/lib/systemd/system/lvmetad.socket"
  install -d -m755 "${pkgdir}/usr/lib/systemd/system/sockets.target.wants"
  ln -sf /usr/lib/systemd/system/lvmetad.socket "${pkgdir}/usr/lib/systemd/system/sockets.target.wants/lvmetad.socket"
  # enable lvmetad
  sed 's|use_lvmetad = 0|use_lvmetad = 1|' -i "${pkgdir}/etc/lvm/lvm.conf"
}
